﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Telerik.Windows.Controls;
using DunSilverlight.Comm;
using DunSilverlight.ViewModel;

namespace DunSilverlight.Views
{
    public partial class RoleForm : UserControl
    {
        RoleService.RoleServiceClient ser = new RoleService.RoleServiceClient();

        RoleModel obj = new RoleModel();
        public RoleForm()
        {
            InitializeComponent();
            ser.SaveOrUpdateCompleted += new EventHandler<RoleService.SaveOrUpdateCompletedEventArgs>(ser_SaveOrUpdateCompleted);
            this.DataContext = obj;
        }

        void ser_SaveOrUpdateCompleted(object sender, RoleService.SaveOrUpdateCompletedEventArgs e)
        {
            (this.Parent as RadWindow).Close();
        }


        private void Save_Click(object sender, RoutedEventArgs e)
        {
            if (obj.Validation())
            {
                var entity = obj.ToEntity();
                ser.SaveOrUpdateAsync(JsonSerializerHelper.EntityToJson(entity));
            }
            else
            {
                Tools.ShowMessage("输入格式不正确", "", false);
            }
           
        }

        private void Cancel_Click(object sender, RoutedEventArgs e)
        {
            (this.Parent as RadWindow).Close();
        }

    }
}
